#! /usr/bin/env node

const fs = require('fs')
const path = require('path')
const inquirer = require('inquirer')
const ejs = require('ejs')

inquirer.prompt([
    {
        type: 'input',
        name: 'name',
        message: 'please input project name',
        default: 'my-project'
    },
    {
        type: 'input',
        name: 'author',
        message: 'please input author\'s name',
        default: 'author'
    },
    {
        type: 'input',
        name: 'email',
        message: 'please input author\' email',
    }
]).then(answers => {
    const tmplDir = path.join(__dirname, 'templates')
    const destDir = process.cwd()
    fs.readdir(tmplDir, (err, files) => {
        if (err) throw err
        files.forEach(file => {
            ejs.renderFile(path.join(tmplDir, file), answers, (err, result) => {
                if (err) throw err
                fs.writeFileSync(path.join(destDir, file), result)
            })
        })
    })
})